<?php
    session_start();
    function connectSSO(){
      include "sql-profile.php";
      
      if ($db_port!="") {
          $db = mysql_connect($db_host.":".$db_port, $db_user, $db_password) or header("Location: http://".$_SERVER["SERVER_NAME"]."/down.html");
      }else{
          $db = mysql_connect($db_host, $db_user, $db_password) or header("Location: http://".$_SERVER["SERVER_NAME"]."/down.html");
      }
      $conn = mysqli_connect($db_host, $db_user, $db_password, $db_name);
      return $conn;
    }

    function readCookie(){
      if(isset($_COOKIE["c_islogin"])&&
        ($_SESSION["ses_login"]!= base64_decode($_COOKIE["c_islogin"])||
          $_SESSION["ses_idRole"]!= base64_decode($_COOKIE["c_idrole"])||
          $_SESSION["ses_idUser"]!= base64_decode($_COOKIE["c_iduser"]))){

        $_SESSION["ses_login"] = base64_decode($_COOKIE["c_islogin"]);
        $_SESSION["ses_idUser"] = base64_decode($_COOKIE["c_iduser"]);
        $_SESSION["ses_userType"] = base64_decode($_COOKIE["c_type"]);
        $_SESSION["ses_pID"] = base64_decode($_COOKIE["c_pid"]);
        $_SESSION["ses_idRole"] = base64_decode($_COOKIE["c_idrole"]);
        header("Location: http://$_SERVER[SERVER_NAME]");

      }
    }

    function isLogin(){
      if(!isset($_COOKIE["c_islogin"])&&isset($_SESSION["ses_login"])){
        session_destroy();
        header("Location: http://$_SERVER[SERVER_NAME]");
      }
    }

    function fileAccess(){
        
        $conn = connectSSO();

        $filePath = str_replace("/","",$_SERVER["SCRIPT_NAME"]);
        
        $sqlAccess = "SELECT * FROM tb_file a
                        LEFT JOIN tb_role_access b
                        ON b.id_file = a.id_file
                        LEFT JOIN tb_user_role c
                        ON c.id_role = b.id_role
                        WHERE a.file_path = '".$filePath."' AND 
                             a.id_sim = '".$_SESSION["ses_idSim"]."' AND
                             c.id_user = '".$_SESSION["ses_idUser"]."' AND 
                             b.id_role = '".$_SESSION["ses_idRole"]."'";
        $queryAccess = mysqli_query($conn, $sqlAccess);
        $banyakAccess = mysqli_num_rows($queryAccess);
        
        if($banyakAccess==0){
            //echo $sqlAccess;
            //echo $filePath;
            header("Location: includes/sso/file-not-found.php");
        }
                
    }
    
    function navBar(){
        $conn = connectSSO();

        $sqlSSO = "SELECT * FROM tb_sim a WHERE a.id_sim IN (SELECT id_sim FROM tb_opt)";
        $querySSO = mysqli_query($conn, $sqlSSO);
        $barisSSO = mysqli_fetch_array($querySSO);
?>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container-fluid">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <?php
            $sql = "SELECT * FROM tb_opt a
                    LEFT JOIN tb_sim b
                    ON b.id_sim = a.id_sim";
            $query = mysqli_query($conn, $sql);
            $baris = mysqli_fetch_array($query);
          ?>
          <a class="brand" href="<?php echo $baris["url"]; ?>"><img src="<?php echo $baris["url"]."/img/logo.png"; ?>" style="margin-top:-7px; margin-bottom:-5px;"></a>
          <div class="nav-collapse collapse">            
            <ul class="nav pull-right">
<?php
            if(isset($_SESSION["ses_login"])){
?>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-th-large icon-white"></i></a>
                <ul class="dropdown-menu">
                    <?php
                        $sqlSim = "SELECT DISTINCT c.* FROM tb_file a
                                    LEFT JOIN tb_role_access b
                                    ON b.id_file = a.id_file
                                    LEFT JOIN tb_sim c
                                    ON c.id_sim = a.id_sim
                                    WHERE b.id_role = '".$_SESSION["ses_idRole"]."'";
                        $querySim = mysqli_query($conn, $sqlSim);
                        while($barisSim = mysqli_fetch_array($querySim)){
?>
                    <li><a class="pindah-sim" rel="<?php echo $barisSim["id_sim"];?>" href="<?php echo $barisSim["url"]."/".$barisSim["url_home"];?>"><?php echo $barisSim["name_sim"];?></a></li>
<?php
                        }
                    ?>
                </ul>
              </li>

              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <i class="icon-globe icon-white"></i> <span class="" id="jum-notif"></span>
                </a>
                <ul class="dropdown-menu">
                  <li class="divider"></li>
                  <ul id="list-notif" class="header-notif">
                  </ul>
                  <li class="divider"></li>
                  <li style="text-align: center;"><a href="<?php echo $barisSSO["url"];?>/notification.php">See All</a></li>
                </ul>
              </li>

              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <i class="icon-envelope-alt icon-white"></i> <span class="" id="jum-msg"></span>
                </a>
                <ul class="dropdown-menu">
                  <li class="divider"></li>
                  <ul id="list-msg" class="header-notif">
                  </ul>
                  <li class="divider"></li>
                  <li style="text-align: center;"><a href="<?php echo $barisSSO["url"];?>/message.php">See All</a></li>
                </ul>
              </li>
              
              <?php
              
                $sql = "SELECT * FROM tb_user WHERE id_user = '".$_SESSION["ses_idUser"]."'";
                $query = mysqli_query($conn, $sql);
                $baris = mysqli_fetch_array($query);
              
                $image = pictURL($_SESSION["ses_pID"], $_SESSION["ses_userType"], 3);
              ?>
              
               <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> <?php echo $baris["username"];?> <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li>
                    <a href="#"><img src="<?php echo $image; ?>" class="img-rounded"> <?php echo $baris["username"];?></a>                  
                  </li>
                  <li class="divider"></li>
                    <?php
                        $sqlRole = "SELECT a.* FROM tb_role a
                                    LEFT JOIN tb_user_role b
                                    ON b.id_role = a.id_role
                                    WHERE b.id_user = '".$_SESSION["ses_idUser"]."'";
                        $queryRole = mysqli_query($conn, $sqlRole);
                        while($barisRole = mysqli_fetch_array($queryRole)){
?>
                            <li <?php echo $_SESSION["ses_idRole"]==$barisRole["id_role"]?"class='disabled'":""?>><a class="role-select" href="#" rel="<?php echo $barisRole["id_role"];?>"><?php echo $barisRole["role_name"]; echo $_SESSION["ses_idRole"]==$barisRole["id_role"]?"<i class='icon-ok'></i>":''?></a></li>
<?php
                        }
                    ?>
                  <li class="divider"></li>
                  <li><a href="#">Dashboard</a></li>
                  <li><a href="editprofil_user.html">Pengaturan akun</a></li>
                  <li><a href="includes/sso/login-logout.php?op=logout" id="logout">Logout</a></li>
                </ul>
              </li>
<?php
            }else{
?>
              <li class="dropdown">
                <a class="dropdown-toggle" id="login-toggle" href="#" data-toggle="dropdown">Login <strong class="caret"></strong></a>
                <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
                  <!-- Login form here -->

                  <form id="login-form" action="includes/login-logout.php?op=login" method="post" accept-charset="UTF-8">
                    <input id="user_username" style="margin-bottom: 15px;" type="text" name="user" placeholder="Username" />
                    <input id="user_password" style="margin-bottom: 15px;" type="password" name="pass" placeholder="Password" />                   
                    <br />
                    <input class="btn btn-primary" style="clear: left; height: 32px; font-size: 13px;" type="submit" name="commit" value="Login" />                    
                    <input class="btn btn-primary btn-danger" style="clear: left; height: 32px; font-size: 13px;" type="submit" name="commit" value="Lupa Password" />
                  </form>

                </div>
              </li>
<?php                
            }
?>
            </ul>  					

           </div><!--/.nav-collapse -->
        </div>
      </div>
      
    </div>
<?php
    }
    
    function sideBar(){
        $conn = connectSSO();
        $sqlAccess = "SELECT a.id_menu, a.name_menu, a.type, b.file_path, a.icon, a.indeks, c.id_role, d.id_user
                      FROM tb_menu a 
                      LEFT JOIN tb_file b 
                        ON b.id_file = a.id_file 
                      LEFT JOIN tb_role_access c 
                        ON c.id_file = b.id_file 
                      LEFT JOIN tb_user_role d 
                        ON d.id_role = c.id_role 
                        WHERE  
                             b.id_sim = '".$_SESSION["ses_idSim"]."' AND
                             d.id_user = '".$_SESSION["ses_idUser"]."' AND 
                             c.id_role = '".$_SESSION["ses_idRole"]."' OR 
                             ISNULL(a.id_file) ORDER BY a.indeks ASC";
                             // echo $sqlAccess;
        $queryAccess = mysqli_query($conn, $sqlAccess);
        $banyakAccess=0;
        while ($barisAccess = mysqli_fetch_array($queryAccess)) {
            $banyakAccess++;
        }
        if($_SESSION["ses_idUser"]!=""){
?>
            <div id="sidebar-sso" class="span3">
<?php
          if ($banyakAccess>0) {
?>
      <div class="sidebar-nav-fixed">
        <ul class="nav nav-tabs nav-stacked">
            <div class="control-group">
              <div class="control">
                <div class="input-append">
                  <input type="text" class="span10" id="searh-sidebar" placeholder="Search Menu">
                  <span class="add-on"><i class="icon-search"></i></span>
                </div>
              </div>
            </div>
<?php
            $queryAccess = mysqli_query($conn, $sqlAccess);
            while($barisAccess = mysqli_fetch_array($queryAccess)){
                // echo $barisAccess['type'];
                if($barisAccess["type"]==1){
                  $sqlSub = "SELECT * FROM tb_menu_sub a
                            LEFT JOIN tb_file b
                            ON b.id_file = a.id_file
                            LEFT JOIN tb_role_access c 
                              ON c.id_file = b.id_file 
                            LEFT JOIN tb_user_role d 
                              ON d.id_role = c.id_role 
                            WHERE a.id_menu = '".$barisAccess["id_menu"]."' AND
                              b.id_sim = '".$_SESSION["ses_idSim"]."' AND
                              d.id_user = '".$_SESSION["ses_idUser"]."' AND
                              c.id_role = '".$_SESSION["ses_idRole"]."' ORDER BY a.indeks ASC";
                  $querySub = mysqli_query($conn, $sqlSub);
                  $banyak = mysqli_num_rows($querySub);
                  if($banyak > 0 ){
?>
                    <li class="side-dropdown"><a href="#"><?php echo $barisAccess["name_menu"] ?><i class="sign pull-right icon-chevron-right"></i></a>
                    <ul class="nav nav-list sub-list" style="display: none;">
<?php
                    $querySub = mysqli_query($conn, $sqlSub);
                    while ($barisSub = mysqli_fetch_array($querySub)) {
?>
                      <li class="list-menu <?php selectedMenu($barisSub["file_path"]);?>">
                        <a href="<?php echo $barisSub["file_path"];?>">
                          <i class="<?php echo $barisSub["icon"];?>"></i>
                          <?php echo $barisSub["name_menu"];?>
                        </a>
                      </li>
<?php
                    }
?>
                    </ul>
<?php
                  }
                }else{
?>
                <li class="list-menu <?php selectedMenu($barisAccess["file_path"]);?>">
                  <a href="<?php echo $barisAccess["file_path"];?>">
                    <i class="<?php echo $barisAccess["icon"];?>"></i> 
                    <?php echo $barisAccess["name_menu"];?>
                  </a>
                </li>
<?php
                }
?>
<?php
            }
?>      
    				</ul>
            <div id="close-sidebar-sso" class="toggle-sidebar-sso tes"><a href="#"><i class="icon-chevron-left"></i></a></div>
    			</div>
<?php
          } 
?>
    		</div>
        <div id="open-sidebar-sso" class="toggle-sidebar-sso well"><a href="#"><i class="icon-chevron-right"></i></a></div>
<?php
        }
    }
    
    function selectedMenu($judul){
  		$file = $_SERVER["SCRIPT_NAME"];
  		$info1 = pathinfo($file);
  		$info2 = pathinfo($judul);
  		$file_name1 = explode("-",$info1["filename"]);
  		$file_name2 = explode("-",$info2["filename"]);
  		if($file_name1[0]==$file_name2[0]){
  			echo"active";
  		}
  	}

    function createNotifRole($header, $url, $idRole){
      $conn = connectSSO();
      $date = date("Y-m-d H:i:s");

      if ($url[0] != '') {
        $urlNotif = $url[0];
      }else{
        $urlNotif = $_SESSION["ses_idSim"];
      }
      $sqlNotif = "INSERT INTO tb_notif(notifier, header, url, id_sim, tanggal) VALUES('".$_SESSION["ses_idUser"]."', '".$header."', '".$url[1]."', '".$urlNotif."', '".$date."')";
      $queryNotif = mysqli_query($conn, $sqlNotif);
      $idNotif = mysqli_insert_id($conn);

      foreach($idRole as $value){
        $sqlRole = "INSERT INTO tb_notif_user(id_notif, id_user, id_role, status) SELECT '".$idNotif."', id_user, '".$value."', '0' FROM tb_user_role WHERE id_role = '".$value."'";
        $queryRole = mysqli_query($conn, $sqlRole);
      }
    }


    /*
      $header:  berupa subjek atau penjelasan kecil mengenai notifikasi
      $url:     url notifikasi tentang kemana user akan diarahkan oleh notifikasi
      $pid:     array yang berisi kombinasi antara pid yang bisa didapat dari fungsi getPid() dengan tipe user
                contoh array('1;2', '2;2', '1;3')
    */
    function createNotifUser($header, $url, $pid){
      $conn = connectSSO();
      $date = date("Y-m-d H:i:s");

      if ($url[0] != '') {
        $urlNotif = $url[0];
      }else{
        $urlNotif = $_SESSION["ses_idSim"];
      }
      $sqlNotif = "INSERT INTO tb_notif(notifier, header, url, id_sim, tanggal) VALUES('".$_SESSION["ses_idUser"]."', '".$header."', '".$url[1]."', '".$urlNotif."', '".$date."')";
      $queryNotif = mysqli_query($conn, $sqlNotif);
      $idNotif = mysqli_insert_id($conn);

      foreach($pid as $value){
        $tes = explode(";", $value);
        $sqlNotifUser = "INSERT INTO tb_notif_user(id_notif, id_user, id_role, status) SELECT '".$idNotif."', id_user, '".$tes[2]."', '0' FROM tb_user WHERE pid = '".$tes[0]."' AND user_type = '".$tes[1]."'";
        $queryNotifUser = mysqli_query($conn, $sqlNotifUser);
      }
    }

    function readNotif(){
      $conn = connectSSO();
      if(isset($_SESSION["ses_idUser"])){
        $url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
        $sql = "SELECT * FROM tb_notif_user a
                LEFT JOIN tb_notif b
                ON b.id_notif = a.id_notif
                LEFT JOIN tb_sim c
                ON c.id_sim = b.id_sim
                WHERE a.id_user = $_SESSION[ses_idUser] AND a.id_role = '$_SESSION[ses_idRole]' AND CONCAT(c.url,b.url) = '$url' AND a.status = 0";
        $query = mysqli_query($conn, $sql);
        if(mysqli_num_rows($query)>0){
          $query = mysqli_query($conn, $sql);
          while($baris = mysqli_fetch_array($query)){
            $sqlRead = "UPDATE tb_notif_user SET status = 1 WHERE id_notif_user = '$baris[id_notif_user]'";
            $queryRead = mysqli_query($conn, $sqlRead);
          }
        }
      }
    }

    function createUser($user, $userType){
      $conn = connectSSO();
      foreach ($user as $key => $value) {
        $username = $value[0];
        $password = md5($value[0]);
        $pid = $value[1];
        $sql = "INSERT INTO tb_user(username, password, user_type, pid) VALUES('".$username."', '".$password."', '".$userType."', '".$pid."')";
        $query = mysqli_query($conn, $sql);
      }
    }

    function getPid($idRole){
      $conn = connectSSO();
      $data = array();
      $sqlGetPID = "SELECT b.pid FROM tb_user_role a
                    LEFT JOIN tb_user b
                    ON b.id_user = a.id_user WHERE a.id_role = '".$idRole."'";
      $queryGetPID = mysqli_query($conn, $sqlGetPID);
      while ($barisGetPID = mysqli_fetch_array($queryGetPID)) {
        array_push($data,$barisGetPID["pid"]);
      }
      return $data;
    }

    function getRole(){
      $conn = connectSSO();
      $data = array();
      $sqlGetRole = "SELECT * FROM tb_role";
      $queryGetRole = mysqli_query($conn, $sqlGetRole);
      while ($barisGetRole = mysqli_fetch_array($queryGetRole)) {
        $data[$barisGetRole["id_role"]] = $barisGetRole["role_name"];
        // array_push($data, array($barisGetRole["id_role"] => $barisGetRole["role_name"]));
      }
      return $data;
    }

    function createFederated($sim, $table){
      $conn = connectSSO();
      foreach ($sim as $value) {
        $sql = "SELECT host, port, username, password, db_name FROM tb_sim WHERE id_sim = '$_SESSION[ses_idSim]'";
        $query = mysqli_query($conn, $sql);
        $baris = mysqli_fetch_array($query);
        $remoteHost = $baris["host"];
        $remoteUser = $baris["username"];
        $remotePass = $baris["password"];
        $remoteDB = $baris["db_name"];
        $remotePort = $baris["port"];
        // echo "mysqli_connect($remoteHost,$remoteUser,$remotePass,$remoteDB,$remotePort)";
        if ($remotePort!="") {
            $connRemote = mysqli_connect($remoteHost,$remoteUser,$remotePass,$remoteDB,$remotePort) or die("gagal");
        }else{
            $connRemote = mysqli_connect($remoteHost,$remoteUser,$remotePass,$remoteDB) or die("gagal");
        }
        if ($connRemote) {
            $sqlRemote = "DESC $table";
            $queryRemote = mysqli_query($connRemote, $sqlRemote);
            $banyakRemote = mysqli_num_rows($queryRemote);
            $queryRemote = mysqli_query($connRemote, $sqlRemote);
            $sqlFederated = "CREATE TABLE f_$table (";
            $i = 1;
            $priArr = array();
            while ($barisRemote = mysqli_fetch_array($queryRemote)) {
                if($barisRemote["Null"]=="NO"){
                    $null = "NOT NULL";
                }elseif(($barisRemote["Null"]=="YES") && ($barisRemote["Default"]=="")){
                    $null = "DEFAULT NULL";
                }else{
                    $null = $barisRemote["Default"];
                }

                if($barisRemote["Key"]!=""){
                    $pri["key"] = $barisRemote["Key"];
                    $pri["nama"] = $barisRemote["Field"];
                    array_push($priArr,$pri);
                }

                $sqlFederated .= $barisRemote["Field"]." ".strtoupper($barisRemote["Type"])." ".$null." ".strtoupper($barisRemote["Extra"]);

                if($i<$banyakRemote){
                    $sqlFederated .= ", ";
                }
                $i++;
            }
            $i = 1;
            foreach ($priArr as $key) {
                if($i==1){  
                  $sqlFederated .= ",";
                  $sqlFederated .= " PRIMARY KEY(";
                }
                if ($key["key"]=="PRI") {
                  $sqlFederated .= "$key[nama]";
                }
                if($i<sizeof($priArr)){
                  $sqlFederated .= ", ";
                }else{
                  $sqlFederated .= ")";
                }
                $i++;
            }
            if ($remotePass!="") { $remotePass .= ":".$remotePass; }
            if ($remotePort!="") { $remoteHost .= ":".$remotePort; }
            $sqlFederated .= ") ENGINE=FEDERATED DEFAULT CHARSET=latin1 CONNECTION='mysql://$remoteUser@$remoteHost/$remoteDB/$table';";
            // echo $sqlFederated;
            
            $sqlLocal = "SELECT host, port, username, password, db_name FROM tb_sim WHERE id_sim = '$value'";
            $queryLocal = mysqli_query($conn, $sqlLocal);
            $barisLocal = mysqli_fetch_array($queryLocal);
            $localHost = $barisLocal["host"];
            $localUser = $barisLocal["username"];
            $localPass = $barisLocal["password"];
            $localDB = $barisLocal["db_name"];
            $localPort = $barisLocal["port"];

            if ($localPort!="") {
                $connLocal = mysqli_connect($localHost,$localUser,$localPass,$localDB,$localPort) or die("gagal");
            }else{
                $connLocal = mysqli_connect($localHost,$localUser,$localPass,$localDB) or die("gagal");
            }

            $sqlDropTable = "DROP TABLE IF EXISTS f_$table";
            $queryDropTable = mysqli_query($connLocal, $sqlDropTable);

            if ($queryDropTable) {
                $queryCreateFederated = mysqli_query($connLocal, $sqlFederated);
                if($queryCreateFederated){
                    echo "sukses";
                }
            }
        }
      }
    }

    function dateTime($datex){

      $dayArr = array(
                    '0' => 'Minggu', 
                    '1' => 'Senin', 
                    '2' => 'Selasa', 
                    '3' => 'Rabu', 
                    '4' => 'Kamis', 
                    '5' => 'Jumat', 
                    '6' => 'Sabtu'
                  );

      $now = time("now");
      $past = strtotime($datex);
      $diff = abs($now - $past);

      $yearNow = date("Y", $now);
      $yearDate = date("Y", $past);
      $yearDiff = abs($yearNow - $yearDate);

      $dayOfWeekNow = date( "w", $now);
      $dayDiff = floor($diff / (60*60*24));

      if ($yearDiff>0) {
        $dateString = date("d M Y", $past);
      }elseif ($dayOfWeekNow < $dayDiff) {
        $dateString = date("d M", $past);
      }elseif ($dayDiff == 0) {
        $dateString = date("H:i", $past);
      }else {
        $dateString = $dayArr[date( "w", $past)];
      }

      return $dateString;
    }

    function pictURL($id, $userType, $imgType){
      $conn = connectSSO();
      switch ($userType) {
        case 1:
          $sqlURL = "SELECT a.url FROM tb_sim a
                      RIGHT JOIN tb_opt b
                        ON a.id_sim = b.dosen_pict";
          $queryURL = mysqli_query($conn, $sqlURL);
          $data = mysqli_fetch_array($queryURL);
          break;

        case 2:
          $sqlURL = "SELECT a.url FROM tb_sim a
                      RIGHT JOIN tb_opt b
                        ON a.id_sim = b.mahasiswa_pict";
          $queryURL = mysqli_query($conn, $sqlURL);
          $data = mysqli_fetch_array($queryURL);
          break;

        case 3:
          $sqlURL = "SELECT a.url FROM tb_sim a
                      RIGHT JOIN tb_opt b
                        ON a.id_sim = b.pegawai_pict";
          $queryURL = mysqli_query($conn, $sqlURL);
          $data = mysqli_fetch_array($queryURL);
          break;
      }
      $folder = $data[0]."/img/";
      switch ($imgType) {
        case 1:
          $image = "resize_";
          break;

        case 2:
          $image = "thumb_";
          break;

        case 3:
          $image = "ico_";
          break;
      }
      $imgFull = $folder.$image.$id.".jpg";
      $imgDefault = $folder.$image."default.jpg";
      $ch = curl_init($imgFull);
      curl_setopt($ch, CURLOPT_NOBODY, true);
      curl_exec($ch);
      $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      if ($retcode == 200) {
        $imageURL = $imgFull."?".time();
      } else {
        $imageURL = $imgDefault."?".time();
      }
      curl_close($ch);
      return $imageURL;
    }

    function logoURL(){
      $conn = connectSSO();
      $sqlURL = "SELECT url FROM tb_sim WHERE id_sim IN (SELECT id_sim FROM tb_opt)";
      $queryURL = mysqli_query($conn, $sqlURL);
      $barisURL = mysqli_fetch_array($queryURL);
      $imgFull = $barisURL["url"]."/img/logo_univ.png";
      $ch = curl_init($imgFull);
      curl_setopt($ch, CURLOPT_NOBODY, true);
      curl_exec($ch);
      $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      if ($retcode == 200) {
        $imageURL = $imgFull."?".time();
      }
      curl_close($ch);
      return $imageURL;
    }

    function getDashboard(){
      $conn = connectSSO();
      $data = array();
      $sqlOpt = "SELECT * FROM tb_opt";
      $queryOpt = mysqli_query($conn, $sqlOpt);
      while($row = mysqli_fetch_assoc($queryOpt)) {   
        foreach ($row as $col => $val) {
            $data[$col] = $val;
        }
      }
      return $data;
    }
?>